package com.palmwindActivity.app;

import java.util.Stack;

import android.view.ViewGroup;

public class ScreenStack {
	
	protected Stack<ViewGroup> screenStack;
	protected IUiShowScreen uiShowScreen;
	public ScreenStack()
	{
		screenStack = new Stack();
	}
	
	public void setUIShowScreen(IUiShowScreen uiShowScreen) 
	{
		this.uiShowScreen = uiShowScreen;
	}

	public void pushAndShowScreen(ViewGroup screen)
	{
		screenStack.push(screen);
		uiShowScreen.showScreen(screen);
	}
	
	public ViewGroup popScreen()
	{
		ViewGroup screen = null;
		if(screenStack.size() > 0)
		{
			screen = screenStack.pop();
		}
		return screen;
	}
	
	public ViewGroup popAndShowScreen()
	{
		ViewGroup screen = null;
		if(screenStack.size() > 1)//sceen stack has more than 2 screen.
		{
			screenStack.pop();
			if(screenStack.size() > 0)
			{
				screen = screenStack.peek();
				uiShowScreen.showScreen(screen);
			}
		}
		return screen;
	}

}
